package com.fita.admin.dao;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.fita.entity.authority.Role;
import com.fita.entity.authority.RoleTemplate;

import java.util.List;

/**
 * 
 * @author Ysy
 */
@Dao("hibernate")
public interface RoleDao {
    
    /**
     * 
     * @param templates
     * @return
     */
    @Query("FROM Role r WHERE r.template IN ( :templates ) AND disabled = false")
    public List<Role> list(@Variable("templates") List<RoleTemplate> templates);
    
    /**
     * 
     * @param template
     * @return
     */
    @Query("SELECT COUNT(*) FROM Role r WHERE r.template = :template")
    public int count(@Variable("template") RoleTemplate template);
    
    /**
     * 
     * @param roleName
     * @return
     */
    @Query("FROM Role r WHERE r.disabled = false AND r.name = :roleName")
    public Role load(@Variable("roleName")String roleName);
    
    /**
     * 
     * @param code
     * @return
     */
    @Query("FROM Role r WHERE r.disabled = false AND r.code = :code")
    public Role loadByCode(@Variable("code")String code);
    
    /**
     * @param id
     * @return
     */
    @Query("FROM Role WHERE disabled = false AND id = :id")
    public Role load(@Variable("id") Long id);
    
}
